//
// C++ Implementation: testProductDB
//
// Description: this tests methods of classes ProductDB and Product
//
//
// Author:  <>, (C) 2007
//
//
//

#include "ProductDB.h"
#include "Product.h"
#include "msg.h"
using namespace msg;

void test_getProductsMoreExpensive()
{
	Step("Here we test a function which allows to view\nwhose products have selling prices above a given value.",0);
	Pause(false);
	ProductDB yo("product.dat");
	float f;
	Step("Let's take the following list of products.");
	cout << yo;
	Pause(false);
	Step("Please give a minimum price");
	cout << "?";
	cin >> f;
	ProductDB higher = yo.getProductsMoreExpensive(f);
	Pause();
	ostringstream o;
	o << "The products found to have selling prices higher or equal to " << f << "$ are:";
	Step(o.str());
	cout << higher;
}




void test_getMoreNumerousProducts()
{
	Step("Here we test a function which allows to view\nthe products which are in a quantity higher than a given value.",0);
	Pause(false);
	ProductDB yo("product.dat");
	float f;
	Step("Let's take the following list of products.");
	cout << yo;
	Pause(false);
	Step("Please give a minimum quantity of products");
	cout << "?";
	cin >> f;
	ProductDB higher = yo.getMoreNumerousProducts(f);
	ostringstream o;
	o<<"The products found to have a quantity higher or equal to " << f << " units are:";
	Step(o.str());
	cout << higher;
	Pause(false); //weird but we must have it here
}



void test_getPredictedProfit()
{
	string connerie;
	ProductDB miyooo("product.dat");
	
	Step("Here we test a function which calculates the profit\nmade if all the stocks of a product were sold.",0);
	Pause();
	Step("Here is the list we work with:");
	cout << miyooo;
	Pause(false);
	Step("Please write one of these products' name: ");
	miyooo.showNames();
	cout<<endl<<"?";
	getline(cin,connerie);
	miyooo.showPredictedProfitOf (connerie);
	Pause(false);
}

void test_showTotalPredictedProfit()
{
	Step("Given the following list:",0);
	ProductDB yoMan("product.dat");
	cout << yoMan;
	Pause(false);
	yoMan.showTotalPredictedProfit();
}

void test_writeTo_OtherFile()
{
	string src,dest;
	Step("The function we test copies a database file\ninto a destination file using ProductDB's methods.",0);
	cout << "Please give a source file name (ex: product.dat):" << endl;
	cout << "?";
	cin >> src;
	ProductDB hop(src);
	if(!hop)// if the database is empty
	{
		cout << "The file does not contain any product or could not open the file, giving up !" << endl;
		Pause(false);
	}
	else
	{
		Step("Please give a destination file name:");
		cout << "?";
		cin >> dest;
		hop.writeTo_OtherFile(dest);
		Pause();
		ProductDB hip(dest);
		Step("Now you can compare by yourself the source and destination file formatted-contents:");
		Pause(false);
		Step("source file:");
		cout << hop;
		Pause(false);
		Step("destination file (clone):");
		cout << hip;
	}
}

int main()
{
	Menu M("testing of classes Product and ProductDB");
	MenuItem m1(test_writeTo_OtherFile,"void ProductDB::writeTo_OtherFile(string dest)");
	MenuItem m2(test_getProductsMoreExpensive,"ProductDB ProductDB::getProductsMoreExpensive(int minSellingPrice)");
	MenuItem m3(test_getMoreNumerousProducts,"ProductDB ProductDB::getMoreNumerousProducts(float minQuantity)");
	MenuItem m4(test_getPredictedProfit,"float Product::getPredictedProfit()");
	MenuItem m5(test_showTotalPredictedProfit,"ProductDB::showTotalPredictedProfit()");
	M.add(m1);M.add(m2);M.add(m3);M.add(m4);M.add(m5);
	M.run();
	return 0;
}

